package com.oa.co.service.impl;
/*
 *                                                     __----~~~~~~~~~~~------___
 *                                    .  .   ~~//====......          __--~ ~~
 *                    -.            \_|//     |||\\  ~~~~~~::::... /~
 *                 ___-==_       _-~o~  \/    |||  \\            _/~~-
 *         __---~~~.==~||\=_    -_--~/_-~|-   |\\   \\        _/~
 *     _-~~     .=~    |  \\-_    '-~7  /-   /  ||    \      /
 *   .~       .~       |   \\ -_    /  /-   /   ||      \   /
 *  /  ____  /         |     \\ ~-_/  /|- _/   .||       \ /
 *  |~~    ~~|--~~~~--_ \     ~==-/   | \~--===~~        .\
 *           '         ~-|      /|    |-~\~~       __--~~
 *                       |-~~-_/ |    |   ~\_   _-~            /\
 *                            /  \     \__   \/~                \__
 *                        _--~ _/ | .-~~____--~-/                  ~~==.
 *                       ((->/~   '.|||' -_|    ~~-/ ,              . _||
 *                                  -_     ~\      ~~---l__i__i__i--~~_/
 *                                  _-~-__   ~)  \--______________--~~
 *                                //.-~~~-~_--~- |-------~~~~~~~~
 *                                       //.-~~~--\
 *                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 *
 *                               神兽保佑            永无BUG
 */

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.oa.co.bo.Business_tripBo;
import com.oa.co.common.PageVo;
import com.oa.co.common.R;
import com.oa.co.mapper.BusinessTripMapper;
import com.oa.co.pojo.Business_trip;
import com.oa.co.service.BusinessTripService;
import com.oa.co.vo.ScheduleBarVo;
import org.apache.commons.compress.utils.Lists;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;

/**
 * @author sunXuDong
 * @data 2023/5/8
 */
@Service("businessTripService")
public class BusinessTripServiceImpl implements BusinessTripService {
    @Autowired
    private BusinessTripMapper businessTripMapper;

    @Override
    public R queryAll(Integer province) {
        List<Business_trip> list = businessTripMapper.queryAll(province);
        return list != null ? R.ok().data("list",list):R.error().message("空空");

    }

    @Override
    public R queryProname(String proname) {
        List<Business_trip> list = businessTripMapper.queryProname(proname);
        return list != null ? R.ok().data("list",list):R.error().message("空空");
    }

    @Override
    public R queryApplicant(Integer province) {
        List<Business_trip> list = businessTripMapper.queryApplicant(province);
        return list != null ? R.ok().data("list",list):R.error().message("空空");
    }

    @Override
    public PageVo<Business_trip> btcList(Integer page, Integer limit, String proname, Integer t_id, String place_of_departure, String arrival_point) {
        Business_trip business_trip = new Business_trip();
        business_trip.setT_id(t_id);
        business_trip.setProname(proname);
        business_trip.setPlace_of_departure(place_of_departure);
        business_trip.setArrival_point(arrival_point);
        if (page!=null && limit!=null){
            PageHelper.startPage(page,limit);
            List<Business_trip> list = businessTripMapper.btcList(business_trip);
            PageInfo<Business_trip> pageInfo = new PageInfo<>(list);
            PageVo<Business_trip> pageVo = new PageVo<>(0,"---",pageInfo.getTotal(),pageInfo.getList());

            return pageVo;
        }

        List<Business_trip> list = businessTripMapper.btcList(business_trip);
        PageInfo<Business_trip> pageInfo = new PageInfo<>(list);
        PageVo<Business_trip> pageVo = new PageVo<>(0,"---",pageInfo.getTotal(),pageInfo.getList());

        return pageVo;
    }

    @Override
    public R deleteById(Integer id) {
        Integer del = businessTripMapper.deleteById(id);
        return del==1?R.ok().message("删除成功:"+del):R.error().message("删除失败");
    }

    @Override
    public R update(Business_trip business_trip) {
        Integer upd = businessTripMapper.update(business_trip);
        return upd==1?R.ok().message("修改成功"):R.error().message("修改失败");
    }

    @Override
    public R add(Business_trip business_trip) {
        Integer add = businessTripMapper.add(business_trip);
        return add==1?R.ok().message("添加成功"):R.error().message("添加失败");
    }

    @Override
    public R bar() {
        List<ScheduleBarVo> list = businessTripMapper.bar();
        return R.ok().data("map",list);
    }

    @Override
    public R pPie() {
        List<ScheduleBarVo> list = businessTripMapper.pPie();
        return R.ok().data("map",list);
    }

    @Override
    public R aPie() {
        List<ScheduleBarVo> list = businessTripMapper.aPie();
        List<ScheduleBarVo> list1 = businessTripMapper.pPie();
        List<ScheduleBarVo> scheduleBarVo = new ArrayList<>();
        scheduleBarVo.addAll(list);
        scheduleBarVo.addAll(list1);
        System.out.println(scheduleBarVo);
        return R.ok().data("map",list).data("map1",list1).data("list",scheduleBarVo);

    }

    @Override
    public PageInfo<Business_tripBo> btcListBo(Integer page, Integer limit, String proname, Integer t_id, String place_of_departure, String arrival_point) {
        Business_trip business_trip = new Business_trip();
        business_trip.setT_id(t_id);
        business_trip.setProname(proname);
        business_trip.setPlace_of_departure(place_of_departure);
        business_trip.setArrival_point(arrival_point);
        if (page!=null && limit !=null){
            PageHelper.startPage(page,limit);
            List<Business_tripBo> list = businessTripMapper.btcListBo(business_trip);
            PageInfo<Business_tripBo> pageInfo = new PageInfo<>(list);
            return pageInfo;
        }

        List<Business_tripBo> list = businessTripMapper.btcListBo(business_trip);
        PageInfo<Business_tripBo> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }
}
